package dimension.starry.mixin;

import dimension.starry.event.Events;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = ItemStack.class, priority = 1001)
public class ItemStackMixin {

    @Inject(
        method = "finishUsing(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;",
        at = @At(value = "HEAD")
    )
    public void finishUsingItem(World world, LivingEntity livingEntity, CallbackInfoReturnable<ItemStack> cir) {
        if (livingEntity instanceof PlayerEntity player) {
            ItemStack itemStack = (ItemStack) (Object) this;
            Events.PLAYER_FINISH_USING_ITEM_EVENT.invoker().onPlayerFinishUsingItem(player, itemStack);
        }
    }

}
